package TUILayer;//makes this class a part of the TUILayer package
import java.util.*;
import ModelLayer.Person;

/**
 * User interface class to the AddressBook
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Comments translated into English
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressBookUI
{   

    //private static AddressBookUI adBoUI = new AddressBookUI();
    private Scanner keyboard;
    private Scanner keyboardString;
    
    //constructor which does nothing
    public AddressBookUI()
    {
       this.keyboard = new Scanner(System.in);
       this.keyboardString = new Scanner(System.in);
    }
    
    public int readInt() {
        int i = 0;
        boolean ok = false;
        
        while(!ok) {
            try {
                i = this.keyboard.nextInt();
                ok = true;
            }catch(Exception e) {
                this.keyboard.nextLine();
            }
        }
        return i;
    }
   
    public String readLine() {
        return this.keyboardString.nextLine();
    }
    
    public void writeBlankLine() {
        System.out.println("");
    }
    
    public void clearConsole() {
        System.out.println("\f");
    }
    
    public void writeAddressBookMenu()
    {
        System.out.println("\f *** AddressBook Menu ***");
        System.out.println(" (1) Show information about person");
        System.out.println(" (2) Add person");
        System.out.println(" (3) Delete person");
        System.out.println(" (4) Update person");
        System.out.println(" (5) List all persons");
        System.out.println("");
        System.out.println(" (9) Return");
        System.out.print("\n Make your choice: ");

    }
        
    public void writeEnterToContinue() {
        System.out.print("> Press enter to continue");
    }
    
    public void writeSaveOK() {
        System.out.println("The person was added!");
    }
    
    public void writeInputPersonsID()
    {
        System.out.print(" Id: ");
    }
    
    public void writeInputName()
    {
         System.out.print(" Name: ");
    }
    
    public void writeInputName(String name)
    {
         System.out.print(" Name (" + name + "): ");
    }
   
    public void writeInputPostalCode()
    { 
         System.out.print(" Zipcode: ");
    }
    
    public void writeInputPostalCode(int zipcode)
    { 
         System.out.print(" Zipcode (" + zipcode + "): ");
    }
    
    public void writeInputCity()
    { 
         System.out.print(" City: ");
    }
    
    public void writeInputCity(String city)
    { 
         System.out.print(" City (" + city + "): ");
    } 
    
    public void writeInputPhone()
    {
         System.out.print(" Phone Number: ");
    }
    
    public void writeInputPhone(String phone)
    {
         System.out.print(" Phone Number (" + phone + "): ");
    }
     
    public void writeInputAddress()
    {
        System.out.print(" Address: ");
    }
    
    public void writeInputAddress(String address)
    {
        System.out.print(" Address (" + address + "): ");
    }
    
    public void showId(int id)
    {
        System.out.println("ID of the person: " + id);
    }
    
    public void showName(String name)
    { 
        System.out.println("The name of the person: " + name);
    }
    
    public void showAddress(String address)
    { 
        System.out.println("The address of the person: " + address);
    }
    
    public void writeSelectPersonId() {
        System.out.print("Enter a ID of a person to continue: ");
    }
    
    public void writeCreateNewPerson() {
        System.out.println("Add new user:\n==============");
    }
    
    public void writeAddressbook() {
        System.out.println("\fAddressbook:");
    }
    
    public void writeOutPersons(ArrayList<Person> ppl) {
        
        if(ppl.size() > 0) {
            for(Person p : ppl) {
               System.out.println(p.getId() + ": " + p.getName());
            }
        } else {
            System.out.println("There is no persons in the list!");
        }
    }
    
    public void writePersonDetails(Person person) {
        System.out.println("=== Person details ===");
        System.out.println("Id: " + person.getId());
        System.out.println("Name: " + person.getName());
        System.out.println("Address: " + person.getAddress());
        System.out.println("Zipcode: " + person.getZipcode());
        System.out.println("City: " + person.getCity());
        System.out.println("Phone: " + person.getPhone());
    }
}